﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Data.SqlClient;
using ZWL.DBUtility;//请先添加引用

namespace ZWL.BLL
{
   public  class SC_Car
    {
        #region Model
        public SC_Car() { }
        private int _id;
        private string _CarPaiHao;
        private string _SuoShuDanWei;
        private string _ZhuangTai;
        private string _CarXingHao;
        private string _CarLeiXing;
        private string _CarGuiGe;
        private string _CarDanWei;
        private string _FaDongJi;
        private string _DaJiaHao;
        private int _HeDingZaiKe;
        private float _ZhengBeiZhiLiang;
        private float _HeDingZaiZhiLiang;
        private float _PaiLiangGongLv;
        private float _YuanZhi;
        private string _ChangMing;
        private float _ChuChangJiaGe;
        private DateTime _ChuCHangDate;
        private DateTime _JianCheDate;
        private DateTime _FristDengJiDate;
        private DateTime _BaoXianDaoQiDate;
        private string _BZ;

       
        public int ID
        {
            get { return _id; }
            set { _id = value; }
        }
        

        public string CarPaiHao1
        {
            get { return _CarPaiHao; }
            set { _CarPaiHao = value; }
        }

        public string CarPaiHao
        {
            get { return CarPaiHao1; }
            set { CarPaiHao1 = value; }
        }
       

        public string SuoShuDanWei
        {
            get { return _SuoShuDanWei; }
            set { _SuoShuDanWei = value; }
        }
       

        public string ZhuangTai
        {
            get { return _ZhuangTai; }
            set { _ZhuangTai = value; }
        }
        

        public string CarXingHao
        {
            get { return _CarXingHao; }
            set { _CarXingHao = value; }
        }
       

        public string CarLeiXing
        {
            get { return _CarLeiXing; }
            set { _CarLeiXing = value; }
        }
        

        public string CarGuiGe
        {
            get { return _CarGuiGe; }
            set { _CarGuiGe = value; }
        }
       

        public string CarDanWei
        {
            get { return _CarDanWei; }
            set { _CarDanWei = value; }
        }
        

        public string FaDongJi
        {
            get { return _FaDongJi; }
            set { _FaDongJi = value; }
        }
       

        public string DaJiaHao
        {
            get { return _DaJiaHao; }
            set { _DaJiaHao = value; }
        }
        

        public int HeDingZaiKe
        {
            get { return _HeDingZaiKe; }
            set { _HeDingZaiKe = value; }
        }
       

        public float ZhengBeiZhiLiang
        {
            get { return _ZhengBeiZhiLiang; }
            set { _ZhengBeiZhiLiang = value; }
        }
       

        public float HeDingZaiZhiLiang
        {
            get { return _HeDingZaiZhiLiang; }
            set { _HeDingZaiZhiLiang = value; }
        }
        

        public float PaiLiangGongLv
        {
            get { return _PaiLiangGongLv; }
            set { _PaiLiangGongLv = value; }
        }
       

        public float YuanZhi
        {
            get { return _YuanZhi; }
            set { _YuanZhi = value; }
        }
        

        public string ChangMing
        {
            get { return _ChangMing; }
            set { _ChangMing = value; }
        }
        

        public float ChuChangJiaGe
        {
            get { return _ChuChangJiaGe; }
            set { _ChuChangJiaGe = value; }
        }
       

        public DateTime ChuCHangDate
        {
            get { return _ChuCHangDate; }
            set { _ChuCHangDate = value; }
        }
       

        public DateTime JianCheDate
        {
            get { return _JianCheDate; }
            set { _JianCheDate = value; }
        }
       

        public DateTime FristDengJiDate
        {
            get { return _FristDengJiDate; }
            set { _FristDengJiDate = value; }
        }
       

        public DateTime BaoXianDaoQiDate
        {
            get { return _BaoXianDaoQiDate; }
            set { _BaoXianDaoQiDate = value; }
        }
        public string BZ
        {
            get { return _BZ; }
            set { _BZ = value; }
        }

         #endregion Model
        #region  成员方法

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public SC_Car(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,CarPaiHao,SuoShuDanWei,ZhuangTai,CarXingHao,CarLeiXing,CarGuiGe,CarDanWei,FaDongJi,DaJiaHao,HeDingZaiKe,ZhengBeiZhiLiang,HeDingZaiZhiLiang,PaiLiangGongLv,YuanZhi,ChangMing,ChuChangJiaGe,ChuCHangDate,JianCheDate,FristDengJiDate,BaoXianDaoQiDate,BZ ");
            strSql.Append(" FROM SC_Car ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = ID;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                CarPaiHao = ds.Tables[0].Rows[0]["CarPaiHao"].ToString() != "" ? ds.Tables[0].Rows[0]["CarPaiHao"].ToString() : "";
                SuoShuDanWei = ds.Tables[0].Rows[0]["SuoShuDanWei"].ToString() != "" ? ds.Tables[0].Rows[0]["SuoShuDanWei"].ToString() : "";
                ZhuangTai = ds.Tables[0].Rows[0]["ZhuangTai"].ToString() != "" ? ds.Tables[0].Rows[0]["ZhuangTai"].ToString() : "";
                CarXingHao = ds.Tables[0].Rows[0]["CarXingHao"].ToString() != "" ? ds.Tables[0].Rows[0]["CarXingHao"].ToString() : "";
                CarLeiXing = ds.Tables[0].Rows[0]["CarLeiXing"].ToString() != "" ? ds.Tables[0].Rows[0]["CarLeiXing"].ToString() : "";
                CarGuiGe = ds.Tables[0].Rows[0]["CarGuiGe"].ToString() != "" ? ds.Tables[0].Rows[0]["CarGuiGe"].ToString(): "";
                CarDanWei = ds.Tables[0].Rows[0]["CarDanWei"].ToString() != "" ? ds.Tables[0].Rows[0]["CarDanWei"].ToString() : "";
                FaDongJi = ds.Tables[0].Rows[0]["FaDongJi"].ToString() != "" ? ds.Tables[0].Rows[0]["FaDongJi"].ToString() : "";
                DaJiaHao = ds.Tables[0].Rows[0]["DaJiaHao"].ToString() != "" ? ds.Tables[0].Rows[0]["DaJiaHao"].ToString() : "";
                HeDingZaiKe = ds.Tables[0].Rows[0]["HeDingZaiKe"].ToString() != "" ?int.Parse(ds.Tables[0].Rows[0]["HeDingZaiKe"].ToString()) : 0;
                ZhengBeiZhiLiang = ds.Tables[0].Rows[0]["ZhengBeiZhiLiang"].ToString() != "" ? float.Parse(ds.Tables[0].Rows[0]["ZhengBeiZhiLiang"].ToString()) : 0;
                HeDingZaiZhiLiang = ds.Tables[0].Rows[0]["HeDingZaiZhiLiang"].ToString() != "" ? float.Parse(ds.Tables[0].Rows[0]["HeDingZaiZhiLiang"].ToString()) : 0;
                PaiLiangGongLv = ds.Tables[0].Rows[0]["PaiLiangGongLv"].ToString() != "" ? float.Parse(ds.Tables[0].Rows[0]["PaiLiangGongLv"].ToString()) : 0;
                YuanZhi = ds.Tables[0].Rows[0]["YuanZhi"].ToString() != "" ? float.Parse(ds.Tables[0].Rows[0]["YuanZhi"].ToString()) : 0;
                ChangMing = ds.Tables[0].Rows[0]["ChangMing"].ToString() != "" ? ds.Tables[0].Rows[0]["ChangMing"].ToString() : "";
                ChuChangJiaGe = ds.Tables[0].Rows[0]["ChuChangJiaGe"].ToString() != "" ?float.Parse(ds.Tables[0].Rows[0]["ChuChangJiaGe"].ToString()) : 0;
                if (ds.Tables[0].Rows[0]["ChuCHangDate"].ToString() != "")
                {
                    ChuCHangDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["ChuCHangDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["JianCheDate"].ToString() != "")
                {
                    JianCheDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["JianCheDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FristDengJiDate"].ToString() != "")
                {
                    FristDengJiDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["FristDengJiDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["BaoXianDaoQiDate"].ToString() != "")
                {
                    BaoXianDaoQiDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["BaoXianDaoQiDate"].ToString());
                }
                
                BZ = ds.Tables[0].Rows[0]["BZ"].ToString() != "" ? ds.Tables[0].Rows[0]["BZ"].ToString() : "";



            }
        }

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("ID", "SC_Car");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from SC_Car");
            strSql.Append(" where ID=@ID ");

            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = ID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into SC_Car(");
            strSql.Append("CarPaiHao,SuoShuDanWei,ZhuangTai,CarXingHao,CarLeiXing,CarGuiGe,CarDanWei,FaDongJi,DaJiaHao,HeDingZaiKe,ZhengBeiZhiLiang,HeDingZaiZhiLiang,PaiLiangGongLv,YuanZhi,ChangMing,ChuChangJiaGe,ChuCHangDate,JianCheDate,FristDengJiDate,BaoXianDaoQiDate,BZ)");
            strSql.Append(" values (");
            strSql.Append("@CarPaiHao,@SuoShuDanWei,@ZhuangTai,@CarXingHao,@CarLeiXing,@CarGuiGe,@CarDanWei,@FaDongJi,@DaJiaHao,@HeDingZaiKe,@ZhengBeiZhiLiang,@HeDingZaiZhiLiang,@PaiLiangGongLv,@YuanZhi,@ChangMing,@ChuChangJiaGe,@ChuCHangDate,@JianCheDate,@FristDengJiDate,@BaoXianDaoQiDate,@BZ)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@CarPaiHao", SqlDbType.VarChar,50),
					new SqlParameter("@SuoShuDanWei", SqlDbType.VarChar,50),
					new SqlParameter("@ZhuangTai", SqlDbType.VarChar,50),
					new SqlParameter("@CarXingHao", SqlDbType.VarChar,50),
					new SqlParameter("@CarLeiXing", SqlDbType.VarChar,50),
					new SqlParameter("@CarGuiGe", SqlDbType.VarChar,50),
					new SqlParameter("@CarDanWei", SqlDbType.VarChar,50),
					new SqlParameter("@FaDongJi", SqlDbType.VarChar,50),
					new SqlParameter("@DaJiaHao", SqlDbType.VarChar,50),
                    new SqlParameter("@HeDingZaiKe", SqlDbType.Int),
                    new SqlParameter("@ZhengBeiZhiLiang", SqlDbType.Float),
                    new SqlParameter("@HeDingZaiZhiLiang",SqlDbType.Float),
                    new SqlParameter("@PaiLiangGongLv", SqlDbType.Float),
                    new SqlParameter("@YuanZhi", SqlDbType.Float),
                    new SqlParameter("@ChangMing", SqlDbType.VarChar,50),
                    new SqlParameter("@ChuChangJiaGe", SqlDbType.Float),
                    new SqlParameter("@ChuCHangDate", SqlDbType.DateTime),
                    new SqlParameter("@JianCheDate", SqlDbType.DateTime),
                    new SqlParameter("@FristDengJiDate", SqlDbType.DateTime),
                    new SqlParameter("@BaoXianDaoQiDate", SqlDbType.DateTime),
                    new SqlParameter("@BZ", SqlDbType.VarChar,100)};

            parameters[0].Value = CarPaiHao;
            parameters[1].Value = SuoShuDanWei;
            parameters[2].Value = ZhuangTai;
            parameters[3].Value = CarXingHao;
            parameters[4].Value = CarLeiXing;
            parameters[5].Value = CarGuiGe;
            parameters[6].Value = CarDanWei;
            parameters[7].Value = FaDongJi;
            parameters[8].Value = DaJiaHao;
            parameters[9].Value = HeDingZaiKe;
            parameters[10].Value = ZhengBeiZhiLiang;
            parameters[11].Value = HeDingZaiZhiLiang;
            parameters[12].Value = PaiLiangGongLv;
            parameters[13].Value = YuanZhi;
            parameters[14].Value = ChangMing;
            parameters[15].Value = ChuChangJiaGe;
            parameters[16].Value = ChuCHangDate;
            parameters[17].Value = JianCheDate;
            parameters[18].Value = FristDengJiDate;
            parameters[19].Value = BaoXianDaoQiDate;
            parameters[20].Value = BZ;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 1;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update SC_Car set ");
            strSql.Append("CarPaiHao=@CarPaiHao,");
            strSql.Append("SuoShuDanWei=@SuoShuDanWei,");
            strSql.Append("ZhuangTai=@ZhuangTai,");
            strSql.Append("CarLeiXing=@CarLeiXing,");
            strSql.Append("CarGuiGe=@CarGuiGe,");
            strSql.Append("CarDanWei=@CarDanWei,");
            strSql.Append("FaDongJi=@FaDongJi,");
            strSql.Append("DaJiaHao=@DaJiaHao,");
            strSql.Append("HeDingZaiKe=@HeDingZaiKe");
            strSql.Append("ZhengBeiZhiLiang=@ZhengBeiZhiLiang");
            strSql.Append("HeDingZaiZhiLiang=@HeDingZaiZhiLiang");
            strSql.Append("PaiLiangGongLv=@PaiLiangGongLv");
            strSql.Append("YuanZhi=@YuanZhi");
            strSql.Append("ChangMing=@ChangMing");
            strSql.Append("ChuChangJiaGe=@ChuChangJiaGe");
            strSql.Append("ChuCHangDate=@ChuCHangDate");
            strSql.Append("JianCheDate=@JianCheDate");
            strSql.Append("FristDengJiDate=@FristDengJiDate");
            strSql.Append("BaoXianDaoQiDate=@BaoXianDaoQiDate");
            strSql.Append("BZ=@BZ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@CarPaiHao", SqlDbType.VarChar,50),
					new SqlParameter("@SuoShuDanWei", SqlDbType.VarChar,50),
					new SqlParameter("@ZhuangTai", SqlDbType.VarChar,50),
					new SqlParameter("@CarXingHao", SqlDbType.VarChar,50),
					new SqlParameter("@CarLeiXing", SqlDbType.VarChar,50),
					new SqlParameter("@CarGuiGe", SqlDbType.VarChar,50),
					new SqlParameter("@CarDanWei", SqlDbType.VarChar,50),
					new SqlParameter("@FaDongJi", SqlDbType.VarChar,50),
					new SqlParameter("@DaJiaHao", SqlDbType.VarChar,50),
                    new SqlParameter("@HeDingZaiKe", SqlDbType.Int),
                    new SqlParameter("@ZhengBeiZhiLiang", SqlDbType.Float),
                    new SqlParameter("@HeDingZaiZhiLiang",SqlDbType.Float),
                    new SqlParameter("@PaiLiangGongLv", SqlDbType.Float),
                    new SqlParameter("@YuanZhi", SqlDbType.Float),
                    new SqlParameter("@ChangMing", SqlDbType.VarChar,50),
                    new SqlParameter("@ChuChangJiaGe", SqlDbType.Float),
                    new SqlParameter("@ChuCHangDate", SqlDbType.DateTime),
                    new SqlParameter("@JianCheDate", SqlDbType.DateTime),
                    new SqlParameter("@FristDengJiDate", SqlDbType.DateTime),
                    new SqlParameter("@BaoXianDaoQiDate", SqlDbType.DateTime),
                    new SqlParameter("@BZ", SqlDbType.VarChar,100)};
            parameters[0].Value = ID;
            parameters[1].Value = CarPaiHao;
            parameters[2].Value = SuoShuDanWei;
            parameters[3].Value = ZhuangTai;
            parameters[4].Value = CarXingHao;
            parameters[5].Value = CarLeiXing;
            parameters[6].Value = CarGuiGe;
            parameters[7].Value = CarDanWei;
            parameters[8].Value = FaDongJi;
            parameters[8].Value = DaJiaHao;
            parameters[10].Value = HeDingZaiKe;
            parameters[11].Value = ZhengBeiZhiLiang;
            parameters[12].Value = HeDingZaiZhiLiang;
            parameters[13].Value = PaiLiangGongLv;
            parameters[14].Value = YuanZhi;
            parameters[15].Value = ChangMing;
            parameters[16].Value = ChuChangJiaGe;
            parameters[17].Value = ChuCHangDate;
            parameters[18].Value = JianCheDate;
            parameters[18].Value = FristDengJiDate;
            parameters[21].Value = BZ;


            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from SC_Car ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = ID;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,CarPaiHao,SuoShuDanWei,ZhuangTai,CarXingHao,CarLeiXing,CarGuiGe,CarDanWei,FaDongJi,DaJiaHao,HeDingZaiKe,ZhengBeiZhiLiang,HeDingZaiZhiLiang,PaiLiangGongLv,YuanZhi,ChangMing,ChuChangJiaGe,ChuCHangDate,JianCheDate,FristDengJiDate,BaoXianDaoQiDate,BZ ");
            strSql.Append(" FROM SC_Car ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = ID;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                CarPaiHao = ds.Tables[0].Rows[0]["CarPaiHao"].ToString() != "" ? ds.Tables[0].Rows[0]["CarPaiHao"].ToString() : "";
                SuoShuDanWei = ds.Tables[0].Rows[0]["SuoShuDanWei"].ToString() != "" ? ds.Tables[0].Rows[0]["SuoShuDanWei"].ToString() : "";
                ZhuangTai = ds.Tables[0].Rows[0]["ZhuangTai"].ToString() != "" ? ds.Tables[0].Rows[0]["ZhuangTai"].ToString() : "";
                CarXingHao = ds.Tables[0].Rows[0]["CarXingHao"].ToString() != "" ? ds.Tables[0].Rows[0]["CarXingHao"].ToString() : "";
                CarLeiXing = ds.Tables[0].Rows[0]["CarLeiXing"].ToString() != "" ? ds.Tables[0].Rows[0]["CarLeiXing"].ToString() : "";
                CarGuiGe = ds.Tables[0].Rows[0]["CarGuiGe"].ToString() != "" ? ds.Tables[0].Rows[0]["CarGuiGe"].ToString() : "";
                CarDanWei = ds.Tables[0].Rows[0]["CarDanWei"].ToString() != "" ? ds.Tables[0].Rows[0]["CarDanWei"].ToString() : "";
                FaDongJi = ds.Tables[0].Rows[0]["FaDongJi"].ToString() != "" ? ds.Tables[0].Rows[0]["FaDongJi"].ToString() : "";
                DaJiaHao = ds.Tables[0].Rows[0]["DaJiaHao"].ToString() != "" ? ds.Tables[0].Rows[0]["DaJiaHao"].ToString() : "";
                HeDingZaiKe = ds.Tables[0].Rows[0]["HeDingZaiKe"].ToString() != "" ? int.Parse(ds.Tables[0].Rows[0]["HeDingZaiKe"].ToString()) : 0;
                ZhengBeiZhiLiang = ds.Tables[0].Rows[0]["ZhengBeiZhiLiang"].ToString() != "" ? float.Parse(ds.Tables[0].Rows[0]["ZhengBeiZhiLiang"].ToString()) : 0;
                HeDingZaiZhiLiang = ds.Tables[0].Rows[0]["HeDingZaiZhiLiang"].ToString() != "" ? float.Parse(ds.Tables[0].Rows[0]["HeDingZaiZhiLiang"].ToString()) : 0;
                PaiLiangGongLv = ds.Tables[0].Rows[0]["PaiLiangGongLv"].ToString() != "" ? float.Parse(ds.Tables[0].Rows[0]["PaiLiangGongLv"].ToString()) : 0;
                YuanZhi = ds.Tables[0].Rows[0]["YuanZhi"].ToString() != "" ? float.Parse(ds.Tables[0].Rows[0]["YuanZhi"].ToString()) : 0;
                ChangMing = ds.Tables[0].Rows[0]["ChangMing"].ToString() != "" ? ds.Tables[0].Rows[0]["ChangMing"].ToString() : "";
                ChuChangJiaGe = ds.Tables[0].Rows[0]["ChuChangJiaGe"].ToString() != "" ? float.Parse(ds.Tables[0].Rows[0]["ChuChangJiaGe"].ToString()) : 0;
                if (ds.Tables[0].Rows[0]["ChuCHangDate"].ToString() != "")
                {
                    ChuCHangDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["ChuCHangDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["JianCheDate"].ToString() != "")
                {
                    JianCheDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["JianCheDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FristDengJiDate"].ToString() != "")
                {
                    FristDengJiDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["FristDengJiDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["BaoXianDaoQiDate"].ToString() != "")
                {
                    BaoXianDaoQiDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["BaoXianDaoQiDate"].ToString());
                }
                BZ = ds.Tables[0].Rows[0]["BZ"].ToString() != "" ? ds.Tables[0].Rows[0]["BZ"].ToString() : "";
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM SC_Car ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// Excel数据导入Datable
        /// </summary>
        /// <param name="fileUrl"></param>
        /// <param name="table"></param>
        /// <returns></returns>
        public System.Data.DataTable GetExcelDatatable(string fileUrl, string table)
        {
            //office2007之前 仅支持.xls
            //const string cmdText = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;IMEX=1';";
            //支持.xls和.xlsx，即包括office2010等版本的   HDR=Yes代表第一行是标题，不是数据；
            const string cmdText = "Provider=Microsoft.Ace.OleDb.12.0;Data Source={0};Extended Properties='Excel 12.0; HDR=Yes; IMEX=1'";
            System.Data.DataTable dt = null;
            //建立连接
            OleDbConnection conn = new OleDbConnection(string.Format(cmdText, fileUrl));
            try
            {
                //打开连接
                if (conn.State == ConnectionState.Broken || conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }

                System.Data.DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                //获取Excel的第一个Sheet名称
                string sheetName = schemaTable.Rows[0]["TABLE_NAME"].ToString().Trim();
                //查询sheet中的数据
                string strSql = "select * from [" + sheetName + "]";
                OleDbDataAdapter da = new OleDbDataAdapter(strSql, conn);
                DataSet ds = new DataSet();
                da.Fill(ds, table);
                dt = ds.Tables[0];
                return dt;
            }
            catch (Exception exc)
            {
                throw exc;
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }
        }
        /// <summary>
        /// SqlBulkCopy导入数据到数据库
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public void SqlBulkCopyInsetData(System.Data.DataTable dt)
        {


            //数据库连接
            string strConnection = ConfigurationManager.ConnectionStrings["BDOAConnectionString"].ToString();
            SqlConnection sqlConnection = new SqlConnection(strConnection);
            sqlConnection.Open();

            //声明SqlBulkCopy ,using释放非托管资源
            using (SqlBulkCopy sqlBC = new SqlBulkCopy(strConnection))
            {
                //一次批量的插入的数据量
                sqlBC.BatchSize = 1000;
                //超时之前操作完成所允许的秒数，如果超时则事务不会提交 ，数据将回滚，所有已复制的行都会从目标表中移除
                sqlBC.BulkCopyTimeout = 60;

                //设置要批量写入的表
                sqlBC.DestinationTableName = "SC_Car";

                //自定义的datatable和数据库的字段进行对应
                sqlBC.ColumnMappings.Add("车牌号", "CarPaiHao");
                sqlBC.ColumnMappings.Add("所属单位", "SuoShuDanWei");
                sqlBC.ColumnMappings.Add("状态", "ZhuangTai");
                sqlBC.ColumnMappings.Add("厂牌型号", "CarXingHao");
                sqlBC.ColumnMappings.Add("车辆类型", "CarLeiXing");
                sqlBC.ColumnMappings.Add("规格", "CarGuiGe");
                sqlBC.ColumnMappings.Add("单位", "CarDanWei");
                sqlBC.ColumnMappings.Add("发动机号", "FaDongJi");
                sqlBC.ColumnMappings.Add("大架号", "DaJiaHao");
                sqlBC.ColumnMappings.Add("核定载客（人）", "HeDingZaiKe");
                sqlBC.ColumnMappings.Add("整备质量", "ZhengBeiZhiLiang");
                sqlBC.ColumnMappings.Add("核定载质量", "HeDingZaiZhiLiang");
                sqlBC.ColumnMappings.Add("排量/功率", "PaiLiangGongLv");
                sqlBC.ColumnMappings.Add("原值", "YuanZhi");
                sqlBC.ColumnMappings.Add("厂名", "ChangMing");
                sqlBC.ColumnMappings.Add("出厂价格", "ChuChangJiaGe");
                sqlBC.ColumnMappings.Add("出厂日期", "ChuCHangDate");
                sqlBC.ColumnMappings.Add("检车日期", "JianCheDate");
                sqlBC.ColumnMappings.Add("初次登记日期", "FristDengJiDate");
                sqlBC.ColumnMappings.Add("保险到期日期", "BaoXianDaoQiDate");
                sqlBC.ColumnMappings.Add("备注", "BZ");

                //批量写入
                sqlBC.WriteToServer(dt);
            }
            sqlConnection.Dispose();

        }



        #endregion  成员方法


    }
}
